package com.newasia.user.services;

import com.newasia.user.ISysMenuService;
import com.newasia.user.converter.SysMenuConverter;
import com.newasia.user.dal.entitys.SysMenu;
import com.newasia.user.dal.entitys.SysRole;
import com.newasia.user.dal.persistence.SysMenuMapper;
import com.newasia.user.dto.SysMenuDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class SysMenuServiceImpl implements ISysMenuService{

    @Autowired
    SysMenuMapper sysMenuMapper;

    @Autowired
    SysMenuConverter sysMenuConverter;

    @Override
    public List<SysMenuDto> selectSysMenuByRoleId(Long role_id) {

        log.info("Begin SysRoleServiceImpl.selectSysRoleByUserId: user_id:"+role_id);

        List<SysMenuDto> sysRoleDtoList = new ArrayList<SysMenuDto>();
        SysRole sysUser = new SysRole();
        sysUser.setRoleId(role_id);
        try{
            List<SysMenu> sysRoles = sysMenuMapper.selectSysMenuByRoleId(sysUser);
            if(sysRoles.size()<0){
                return null;
            }
            sysRoleDtoList = sysMenuConverter.menu2List(sysRoles);
        }catch (Exception e){
            log.error("SysRoleServiceImpl.selectSysRoleByUserId Occur Exception :"+e);
        }
        return sysRoleDtoList;
    }
}
